<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>多选选择器</title>
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/index.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/dtree/dtree.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/dtree/font/iconfont.css"/>
</head>
<body>
<div class="page-content-wrap clearfix">
    <input type="hidden" id="resultId"/>
    <input type="hidden" id="resultName"/>
    <form class="layui-form">
        <div class="layui-tab pad0">
            <div class="layui-tab-content pad0">
                <div class="layui-tab-item"></div>
                <div class="layui-tab-item layui-show">
                    <div class="layui-form-item marb5">
                        <label class="layui-form-label w75">关键字：</label>
                        <div class="layui-input-inline marl90 margin0 clearfix">
                            <input type="text" name="searchInput" id="searchInput" placeholder="请输入关键字" autocomplete="off" class="layui-input h34 w163 wi-fl">
                            <button type="button" class="layui-btn layui-btn-normal h34 wi-fl marl6" id="search_btn">搜索</button>
                        </div>
                        <!--树开始-->
                        <div class="cont-dtree dtree-height" style=" padding-left:60px;">
                            <ul id="org" class="dtree" data-id="0" style=""></ul>
                        </div>
                        <!--树结束-->
                    </div>

                </div>
                <div class="layui-tab-item">

                </div>
            </div>
        </div>
        <div class="layui-form-item margin0" style="padding-left: 10px;">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" type="button" id="checkBtn">提交</button>
                <button type="button" id="cancel" class="layui-btn layui-btn-primary">取消</button>
                <button type="button" style="display:none;" class="layui-btn layui-btn-normal" id="save"></button>
            </div>
        </div>
    </form>
</div>


<script src="${s.base}/lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="${s.base}/js/common.js" type="text/javascript" charset="utf-8"></script>
<script>
    layui.use(['form', 'jquery', 'layer', 'dtreeUtil'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery,
            dtreeUtil = layui.dtreeUtil;
        var selectObjctParams = parent.cytSelectObjctParams();
        var dtree = dtreeUtil.baseDtree("#org", '${url}', true);
        dtreeUtil.dTreeClick("org", function (param) {
            $("#resultId").val(param.nodeId);
            $("#resultName").val(param.context);
        });
        $("#checkBtn").bind("click", function () {
            dtreeUtil.getCheckbarNodesParam("org", function (params) {
                if (params.length == 0) {
                    layer.msg("请至少选择一个", {icon: 2});
                    return false;
                }
                var ids = [], names = [];
                for (var key in params) {
                    var param = params[key];
                    if (param.isLeaf) {
                        ids.push(param.nodeId);
                        names.push(param.context);
                    }
                }
                $("#resultId").val(ids.join(","));
                $("#resultName").val(names.join(","));
                $("#save").click();
            })

        });
    });
</script>
</body>

</html>